﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using L2C;

namespace L2C.Controllers.Administrator
{
    [Authorize]
    public class CategoryItemController : Controller
    {
        private L2CEntities db = new L2CEntities();

        //
        // GET: /CategoryItem/

        public ViewResult Index()
        {
            return View(db.Category_Item.ToList());
        }

        //
        // GET: /CategoryItem/Details/5

        public ViewResult Details(int id)
        {
            Category_Item category_item = db.Category_Item.Single(c => c.Category_Id == id);
            return View(category_item);
        }

        //
        // GET: /CategoryItem/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /CategoryItem/Create

        [HttpPost]
        public ActionResult Create(Category_Item category_item)
        {
            if (ModelState.IsValid)
            {
                db.Category_Item.AddObject(category_item);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(category_item);
        }
        
        //
        // GET: /CategoryItem/Edit/5
 
        public ActionResult Edit(int id)
        {
            Category_Item category_item = db.Category_Item.Single(c => c.Category_Id == id);
            return View(category_item);
        }

        //
        // POST: /CategoryItem/Edit/5

        [HttpPost]
        public ActionResult Edit(Category_Item category_item)
        {
            if (ModelState.IsValid)
            {
                db.Category_Item.Attach(category_item);
                db.ObjectStateManager.ChangeObjectState(category_item, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(category_item);
        }

        //
        // GET: /CategoryItem/Delete/5
 
        public ActionResult Delete(int id)
        {
            Category_Item category_item = db.Category_Item.Single(c => c.Category_Id == id);
            return View(category_item);
        }

        //
        // POST: /CategoryItem/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            Category_Item category_item = db.Category_Item.Single(c => c.Category_Id == id);
            db.Category_Item.DeleteObject(category_item);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}